/**
 * Created by CAOTE on 12/11/2016.
 */
/**
 * Created by CAOTE on 12/11/2016.
 */

(function () {
    let app = angular.module("DIBS");
    app.controller('homeCtrl', ['$http', '$scope', '$window', homeCtrl]);
    function homeCtrl($http, $scope, $window) {
        $scope.GLOBAL_ReadOnly = GLOBAL_ReadOnly;
        $scope.chooseTab = function (type) {
            $window.location.href = '/Home#/' + type;
        };
        $scope.serviceTypeForSelect = [];
        $scope.domainList = [];
        getDomainList();
        getServiceTypeList();
        function getDomainList() {
            prepareData('Domain');
        }
        function getServiceTypeList() {
            prepareData('ServiceType');
        }
        function prepareData(dataType) {
            if (dataType === 'Domain') {
                let url = "/getDomain";
                let updateListName = 'domainList';
                let field = 'domainName';
            } else {
                let url = "/getServiceType";
                let updateListName = 'serviceTypeForSelect';
                let field = 'serviceTypeName';
            }
            $http({
                method: "POST",
                url: url
            }).success(function (data, status) {
                $scope[updateListName] = [];
                _.each(data, function (re) {
                    $scope[updateListName].push(re[field]);
                })

            }).error(function (data, status) {
                console.log(data)
            });
        }

    }
})();
